import { AxiosPromise } from 'axios';
import {
  ByteQuery,
  ByteVO,
  ShareRangeQuery,
  TypeUpdateMicroVO,
  ShareRangeVO,
  TypeMicroVO,
  ByteAdd,
  ByteUpdate,
  queryToolsAssetLinkListVO,
  getAppinfoVO
} from './types';
import request from '@/utils/request';

export const listByte = (query: ByteQuery): AxiosPromise<ByteVO[]> => {
  return request({
    url: '/oce/microApp/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询字节小程序详细
 */
export const getByte = (roleId: string | number): AxiosPromise<ByteVO> => {
  return request({
    url: '/oce/microApp/' + roleId,
    method: 'get'
  });
};

/**
 * 新增字节小程序
 */
export const addByte = (data: ByteAdd) => {
  return request({
    url: '/oce/microApp',
    method: 'post',
    data: data
  });
};

/**
 * 修改字节小程序
 */
export const updateByte = (data: ByteUpdate) => {
  return request({
    url: '/oce/microApp',
    method: 'put',
    data: data
  });
};

/**
 * 字节小程序状态修改
 */
export const changeRoleStatus = (roleId: string | number, status: string) => {
  const data = {
    roleId,
    status
  };
  return request({
    url: '/system/role/changeStatus',
    method: 'put',
    data: data
  });
};

/**
 * 删除管理字节小程序
 */
export const delByte = (accountRecordIds: Array<string | number> | string | number) => {
  return request({
    url: '/oce/microApp/' + accountRecordIds,
    method: 'delete'
  });
};

export const shareRangeList = (query: ShareRangeQuery): AxiosPromise<ShareRangeVO[]> => {
  return request({
    url: '/oce/third/queryBpAssetManagementShare',
    method: 'get',
    params: query
  });
};

/**
 * 新增字节小程序
 */
export const createByte = (data: TypeMicroVO) => {
  return request({
    url: '/oce/third/createToolsMicroApp',
    method: 'post',
    data: data
  });
};

/**
 * 获取字节小程序详情内容（链接）
 */

export const queryToolsAssetLinkList = (query: queryToolsAssetLinkListVO) => {
  return request({
    url: '/oce/third/queryToolsAssetLinkList',
    method: 'get',
    params: query
  });
};

/**
 * 更新字节小程序
 */
export const updateToolsMicroApp = (data: TypeUpdateMicroVO) => {
  return request({
    url: '/oce/third/updateToolsMicroApp',
    method: 'post',
    data: data
  });
};

//获取字节小程序
export const getAppinfo = (query: getAppinfoVO) => {
  return request({
    url: '/oce/third/queryToolsMicroApp',
    method: 'get',
    params: query
  });
};
